import 'package:flutter/material.dart';
import 'keep_alive_test_route.dart';

class TabBarViewTestRoute extends StatefulWidget {
  const TabBarViewTestRoute({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _TabBarViewTestRouteState();
}

class _TabBarViewTestRouteState extends State<TabBarViewTestRoute>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;

  final _tabs = <String>["新闻", "历史", "图片"];

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: _tabs.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('TabBarView'),
        bottom: TabBar(
          indicatorWeight: 1.0,

          tabs: _tabs.map((e) => Tab(text: e)).toList(),
          controller: _tabController,
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: _tabs.map((e) {
          return KeepAliveWrapper(
            child: Container(
              alignment: Alignment.center,
              child: Text(e, textScaleFactor: 5),
            ),
          );
        }).toList(),
      ),
    );
  }

  @override
  void deactivate() {
    _tabController.dispose();
    super.deactivate();
  }
}
